package cn.iocoder.yudao.module.biz.controller.admin.htHiddentroubleannexs;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.biz.controller.admin.htHiddentroubleannexs.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.htHiddentroubleannexs.HtHiddentroubleannexsDO;
import cn.iocoder.yudao.module.biz.convert.htHiddentroubleannexs.HtHiddentroubleannexsConvert;
import cn.iocoder.yudao.module.biz.service.htHiddentroubleannexs.HtHiddentroubleannexsService;

@Api(tags = "管理后台 - 隐患附件")
@RestController
@RequestMapping("/biz/ht-hiddentroubleannexs")
@Validated
public class HtHiddentroubleannexsController {

    @Resource
    private HtHiddentroubleannexsService htHiddentroubleannexsService;

    @PostMapping("/create")
    @ApiOperation("创建隐患附件")
    @PreAuthorize("@ss.hasPermission('biz:ht-hiddentroubleannexs:create')")
    public CommonResult<String> createHtHiddentroubleannexs(@Valid @RequestBody HtHiddentroubleannexsCreateReqVO createReqVO) {
        return success(htHiddentroubleannexsService.createHtHiddentroubleannexs(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新隐患附件")
    @PreAuthorize("@ss.hasPermission('biz:ht-hiddentroubleannexs:update')")
    public CommonResult<Boolean> updateHtHiddentroubleannexs(@Valid @RequestBody HtHiddentroubleannexsUpdateReqVO updateReqVO) {
        htHiddentroubleannexsService.updateHtHiddentroubleannexs(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除隐患附件")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:ht-hiddentroubleannexs:delete')")
    public CommonResult<Boolean> deleteHtHiddentroubleannexs(@RequestParam("id") String id) {
        htHiddentroubleannexsService.deleteHtHiddentroubleannexs(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得隐患附件")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:ht-hiddentroubleannexs:query')")
    public CommonResult<HtHiddentroubleannexsRespVO> getHtHiddentroubleannexs(@RequestParam("id") String id) {
        HtHiddentroubleannexsDO htHiddentroubleannexs = htHiddentroubleannexsService.getHtHiddentroubleannexs(id);
        return success(HtHiddentroubleannexsConvert.INSTANCE.convert(htHiddentroubleannexs));
    }

    @GetMapping("/list")
    @ApiOperation("获得隐患附件列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:ht-hiddentroubleannexs:query')")
    public CommonResult<List<HtHiddentroubleannexsRespVO>> getHtHiddentroubleannexsList(@RequestParam("ids") Collection<String> ids) {
        List<HtHiddentroubleannexsDO> list = htHiddentroubleannexsService.getHtHiddentroubleannexsList(ids);
        return success(HtHiddentroubleannexsConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得隐患附件分页")
    @PreAuthorize("@ss.hasPermission('biz:ht-hiddentroubleannexs:query')")
    public CommonResult<PageResult<HtHiddentroubleannexsRespVO>> getHtHiddentroubleannexsPage(@Valid HtHiddentroubleannexsPageReqVO pageVO) {
        PageResult<HtHiddentroubleannexsDO> pageResult = htHiddentroubleannexsService.getHtHiddentroubleannexsPage(pageVO);
        return success(HtHiddentroubleannexsConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出隐患附件 Excel")
    @PreAuthorize("@ss.hasPermission('biz:ht-hiddentroubleannexs:export')")
    @OperateLog(type = EXPORT)
    public void exportHtHiddentroubleannexsExcel(@Valid HtHiddentroubleannexsExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<HtHiddentroubleannexsDO> list = htHiddentroubleannexsService.getHtHiddentroubleannexsList(exportReqVO);
        // 导出 Excel
        List<HtHiddentroubleannexsExcelVO> datas = HtHiddentroubleannexsConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "隐患附件.xls", "数据", HtHiddentroubleannexsExcelVO.class, datas);
    }

}
